﻿
/*----------------------------------------------------------------
 * 创建时间：2023/8/15 15:35:13
 * 作  者：wenlli 
 * 项  目：Minotaur.App.Domains.ViewModel.Table 
 * 描  述：表格列表视图类
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时  间：
 * 修改说明：
 * 
 *----------------------------------------------------------------*/


using Newtonsoft.Json;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Minotaur.App.Domains.ViewModel.Table
{
    /// <summary>
    /// 表格列表视图类
    /// </summary>
    public class TableInfoListViewModel : BindableBase
    {
        /// <summary>
        /// 主键
        /// </summary> 
        public virtual long Autoid { get; set; }

        /// <summary>
        /// 表名
        /// </summary> 
        public virtual string? TableCode { get; set; }

        /// <summary>
        /// 分组类型--人员、组织、职位、自定义
        /// </summary> 
        private string _GroupType;
        /// <summary>
        /// 分组类型--人员、组织、职位、自定义
        /// </summary>
        public string GroupType
        {
            get => _GroupType;
            set
            {
                SetProperty(ref _GroupType, value);
                Dictionary<string, string> map = new Dictionary<string, string>();
                map["employee"] = "人员相关";
                map["oranazition"] = "组织相关";
                map["position"] = "职位相关";
                map["custom"] = "自定义";
                if (!string.IsNullOrEmpty(value))
                {
                    string[] values = JsonConvert.DeserializeObject<string[]>(value);

                    if (values.Any())
                    {
                        foreach (var it in values)
                        {
                            DisGroupType.Add(map[it]);
                        }
                    }
                }
            }
        }
        public virtual List<string> DisGroupType { get; set; } = new List<string>();

        private int? _ViewType;
        /// <summary>
        /// 视图类型
        /// </summary> 
        public int? ViewType
        {
            get => _ViewType; set
            {
                SetProperty(ref _ViewType, value);
                if (value.HasValue)
                {
                    Dictionary<int, string> map = new Dictionary<int, string>();
                    map[0] = "表格";
                    map[1] = "卡片";
                    DisViewType = map[value.Value];
                }
            }
        }
        public string DisViewType { get; set; }

        private bool? _IsPrimary;
        /// <summary>
        /// 是否是主键表
        /// </summary> 
        public bool? IsPrimary
        {
            get => _IsPrimary;
            set
            {
                SetProperty(ref _IsPrimary, value);
                DisIsPrimary = value.HasValue && value.Value ? "主键表" : "外键表";
            }
        }
        public string DisIsPrimary { get; set; }

        /// <summary>
        /// 主键表
        /// </summary> 
        public virtual string? PkTable { get; set; }

        public virtual string CreatorName { get; set; }
        public virtual string Creator { get; set; }
        private bool? _Enable;
        /// <summary>
        /// 是否禁用
        /// </summary> 
        public bool? Enable
        {
            get => _Enable;
            set
            {
                SetProperty(ref _Enable, value);
                if (value.HasValue && value.Value)
                {
                    RowColor = "#108ee9";
                    DisEnable = "启用";
                    ForeRowColor = "Snow";
                }
                else
                {
                    RowColor = "#f56c6c";
                    DisEnable = "禁用";
                    ForeRowColor = "#f56c6c";
                }
            }
        }
        public string DisEnable { get; set; }

        private bool? _IsSystem;
        /// <summary>
        /// 是否是系统表
        /// </summary> 
        public bool? IsSystem
        {
            get => _IsSystem;
            set
            {
                SetProperty(ref _IsSystem, value);
                DisIsSystem = value.HasValue && value.Value ? "系统表" : "自定义表";
            }
        }
        public string DisIsSystem { get; set; }

        /// <summary>
        /// 用于流程
        /// </summary> 
        public virtual bool? Isflow { get; set; }

        /// <summary>
        /// 记录类型
        /// </summary> 
        public virtual bool? Records { get; set; }

        /// <summary>
        /// 流程表名
        /// </summary> 
        public virtual string? FlowTableCode { get; set; }

        /// <summary>
        /// 排序
        /// </summary> 
        public virtual long? Sequence { get; set; }

        /// <summary>
        /// 列表表名
        /// </summary>
        public virtual string TableName { get; set; }

        /// <summary>
        /// 启用/禁用
        /// </summary>
        [Newtonsoft.Json.JsonIgnore()]
        public ICommand EnableOrDisabledCommand => new DelegateCommand<object>(EnableOrDisabledAction);

        /// <summary>
        /// 启用/禁用
        /// </summary>
        [Newtonsoft.Json.JsonIgnore()]
        public Action<object> EnableOrDisabledAction { get; set; }

        /// <summary>
        /// 字段管理
        /// </summary>
        [Newtonsoft.Json.JsonIgnore()]
        public Action<object> FieldsManagerAction { get; set; }

        /// <summary>
        /// 字段管理
        /// </summary>
        [Newtonsoft.Json.JsonIgnore()]
        public ICommand FieldsManageruCommand => new DelegateCommand<object>(FieldsManagerAction);


        /// <summary>
        /// 编辑按钮
        /// </summary>
        [Newtonsoft.Json.JsonIgnore()]
        public Action<object> EditAction { get; set; }

        /// <summary>
        /// 编辑按钮
        /// </summary>
        [Newtonsoft.Json.JsonIgnore()] public ICommand EditCommand => new DelegateCommand<object>(EditAction);

        /// <summary>
        /// 行颜色
        /// </summary>
        public string RowColor { get; set; }

        /// <summary>
        /// 行颜色
        /// </summary>
        public string ForeRowColor { get; set; }

        public string CreatDate { get; set; }

        /// <summary>
        /// 删除命令
        /// </summary>
        [Newtonsoft.Json.JsonIgnore()] 
        public ICommand DeleteCommand => new DelegateCommand<object>(DeleteAction);
        [Newtonsoft.Json.JsonIgnore()]
        public Action<object> DeleteAction { get; set; }

    }
}
